<?php

namespace App\Http\Services;

use App\Http\Model\User;

/**
 * 用户资料
 */
class UserProfileServices extends CommonServices
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取用户资料完成度, 总分值为100
     *
     * @param int $userId 用户id
     * @return int
     */
    public function getCompletion(int $userId): int
    {
        $completion = 0;
        $user = (new User())->get_user($userId, true);
        $user['voice'] = 0;
        $user['tags'] = $user['tags'] ?? [];//我的标签
        if (!$user['tags']) {
            $user['tags'] = $user['other_tags'] ?? [];//他人标签
        }

        $quotas = ['images' => 10, 'nickname' => 10, 'birthday' => 10, 'sign' => 10, 'affective_state' => 10,
            'home' => 10, 'occupation' => 10, 'height' => 10, 'tags' => 10, 'voice' => 10];
        foreach ($quotas as $key => $num) {
            if (isset($user[$key]) && $user[$key]) {
                $completion += $num;
            }
        }

        return $completion > 100 ? 100 : $completion;
    }
}